package com.cwd.arm.infrastructure.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cwd.arm.infrastructure.dao.UserRoleDao;
import com.cwd.arm.infrastructure.mapper.UserRoleMapper;
import com.cwd.arm.infrastructure.po.UserRolePo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* Description:用户角色关联
* Created on 2022年01月01日
* @author  yan
*/
@Service
public class UserRoleDaoImpl extends ServiceImpl<UserRoleMapper, UserRolePo> implements UserRoleDao {


    @Override
    public UserRolePo selectByUserIdAndRoleId(Long userId, Long roleId) {
        QueryWrapper<UserRolePo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("role_id",roleId);
        return list(queryWrapper).get(0);
    }

    @Override
    public void removeByRoleId(Long roleId) {
        QueryWrapper<UserRolePo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id",roleId);
        remove(queryWrapper);
    }

    @Override
    public void removeByUserId(Long userId) {
        QueryWrapper<UserRolePo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        remove(queryWrapper);
    }
}
